<?php
namespace app\common\service\module_manage\netfilter;


use app\common\exception\CustomException;
use think\Db;

class NetfilterSafeRule
{

    /**
     * @name: 删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 16:26:03
     */
    public function init ($host_id)
    {
        Db::name('netfilter_safe_rule')->whereIn('host_id', $host_id)->update(['status' => 1]);
    }

    /**
     * @name: 删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 16:26:03
     */
    public function trunOnOff ($host_id, $rule_id, $status)
    {
        Db::name('netfilter_safe_rule')->whereIn('host_id', $host_id)->whereIn('id', $rule_id)->update(['status' => $status]);
    }

    /**
     * @name: 通过id查询
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 16:32:23
     */
    public function selectById ($host_id, $rule_id, $status = 1)
    {
        $return = Db::name('netfilter_safe_rule')->field('content,status')->whereIn('host_id', $host_id)->whereIn('id', $rule_id)->where('status', $status)->select();
        if(empty($return))
        {
            throw new CustomException('未找到默认规则', 422);
        }
        return $return;
    }

    /**
     * @name: 通过id查询
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 16:32:23
     */
    public function selectByHostId ($host_id)
    {
        $return = Db::name('netfilter_safe_rule')->field('content,status')->whereIn('host_id', $host_id)->select();
        if(empty($return))
        {
            throw new CustomException('未找到默认规则', 422);
        }
        return $return;
    }

    // /**
    //  * @name: windows2012 安全规则
    //  * @Param: 
    //  * @Description: 
    //  * @Author: foo
    //  * @Date: 2020-01-03 16:53:38
    //  */
    // function windows2012 ()
    // {
    //     $return = [
    //         'New-NetFirewallRule -DisplayName "icmpv6in" -Direction Inbound -Action Allow -protocol icmpv6',
    //         'New-NetFirewallRule -DisplayName "icmpv6out" -Direction Outbound -Action Allow -protocol icmpv6',
    //         'New-NetFirewallRule -DisplayName "icmpv4in" -Direction Inbound -Action Allow -protocol icmpv4',
    //         'New-NetFirewallRule -DisplayName "icmpv4out" -Direction Outbound -Action Allow -protocol icmpv4',
    //     ];

    //     return $return;
    // }

    /**
     * @name: 删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-24 11:29:01
     */
    public function del ($host_id_a)
    {
        Db::name('netfilter_safe_rule')->whereIn('host_id', $host_id_a)->delete();
    }
}